package com.kl.model.pojo;

import com.kl.enums.Direct;
import com.kl.enums.TankType;
import com.kl.exceptions.DeathException;
import lombok.Getter;
import lombok.Setter;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * @author CC
 * time 2024-05-15
 * description
 */
public class HeroTank extends Tank implements KeyListener {
    /**
     * 杀敌分数
     */
    @Getter
    @Setter
    private int score;
    @Getter
    @Setter
    private String uid;
    @Setter
    private String name;

    public HeroTank(int x, int y) {
        super(TankType.HERO, x, y);
        this.setSpeed(2) ;
        this.uid= GameSetting.INSTANCE.getUid();
    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    public void keyPressed(KeyEvent e) {
        switch (e.getKeyCode()){
            case KeyEvent.VK_W:
                this.move(this.getX(),this.getY(),this.getSpeed(), Direct.UP);
                break;
            case KeyEvent.VK_A:
                this.move(this.getX(),this.getY(),this.getSpeed(),Direct.LEFT);
                break;
            case KeyEvent.VK_S:
                this.move(this.getX(),this.getY(),this.getSpeed(),Direct.DOWN);
                break;
            case KeyEvent.VK_D:
                this.move(this.getX(),this.getY(),this.getSpeed(),Direct.RIGHT);
                break;
            case KeyEvent.VK_J:
                try {
                    this.attack(getX(),getY(),getDirect(),null,getOrigin());
                }catch (DeathException ex1){
                    return;
                }
                break;
        }


    }

    @Override
    public void keyReleased(KeyEvent e) {

    }
}
